#******************************************************************
#
# Copyright (c) 2018 LG Electronics, Inc.
# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Import('stacksamples_env')

samples_env = stacksamples_env.Clone()

######################################################################
# Build flags
######################################################################
samples_env.PrependUnique(CPPPATH=[
    '../../../../../logger/include',
    '../../../../../include',
    '../../../../../stack/include',
    '../../../../../security/include',
    '../../../../../../oc_logger/include',
    '../'
])

target_os = samples_env.get('TARGET_OS')
if target_os not in ['windows']:
    samples_env.AppendUnique(CXXFLAGS=['-std=c++0x', '-Wall', '-pthread'])

    # Note: 'pthread' is in libc for android.
    if target_os != 'android':
        samples_env.AppendUnique(LIBS=['pthread'])
    samples_env.Append(LINKFLAGS=['-Wl,--no-as-needed'])

if target_os in ['windows', 'msys_nt']:
    samples_env.PrependUnique(LIBS=['coap', 'ocsrm'])
else:
    samples_env.PrependUnique(LIBS=['connectivity_abstraction', 'coap', 'm'])

samples_env.PrependUnique(LIBS=['octbstack'])

if samples_env.get('SECURED') == '1':
    samples_env.AppendUnique(LIBS=['mbedtls', 'mbedx509', 'mbedcrypto'])

if target_os == 'android':
    samples_env.AppendUnique(CXXFLAGS=['-frtti', '-fexceptions'])
    samples_env.AppendUnique(LIBS=['gnustl_shared'])
    samples_env.AppendUnique(
        CPPDEFINES=['_GLIBCXX_USE_C99=1', '_GLIBCXX_HAVE_WCSTOF=1'])

    if not samples_env.get('RELEASE'):
        samples_env.AppendUnique(LIBS=['log'])

if target_os in ['darwin', 'ios']:
    samples_env.AppendUnique(CPPDEFINES=['_DARWIN_C_SOURCE'])

samples_env.AppendUnique(CPPDEFINES=['TB_LOG'])

samples_env.ParseConfig("pkg-config --cflags --libs glib-2.0")
samples_env.ParseConfig("pkg-config --cflags --libs luna-service2")
samples_env.ParseConfig("pkg-config --cflags --libs pbnjson_c")

######################################################################
# Source files and Targets
######################################################################

occlientbasicops = samples_env.Program(
    'occlientbasicops', ['../common.cpp', 'occlientbasicops.cpp'])

ocsamples = [occlientbasicops]
Alias("samples", ocsamples)
samples_env.AppendTarget('samples')

src_dir = samples_env.get('SRC_DIR')
sec_samples_src_dir = src_dir + '/resource/csdk/stack/samples/linux/secure/'
sec_samples_build_dir = samples_env.get(
    'BUILD_DIR') + '/resource/csdk/stack/samples/linux/secure'

samples_env.Alias(
    "install",
    samples_env.Install(sec_samples_build_dir,
                        sec_samples_src_dir + 'oic_svr_db_client_devowner.json'))
samples_env.Alias(
    "install",
    samples_env.Install(sec_samples_build_dir,
                        sec_samples_src_dir + 'oic_svr_db_client_nondevowner.json'))

samples_env.Alias(
    "install",
    samples_env.Install(sec_samples_build_dir,
                        sec_samples_src_dir + 'oic_svr_db_client_devowner.dat'))
samples_env.Alias(
    "install",
    samples_env.Install(sec_samples_build_dir,
                        sec_samples_src_dir + 'oic_svr_db_client_nondevowner.dat'))
